home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NUMBERS.SWG / 0026_MS to IEEE Numbers.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  1KB  |  42 lines

  1. {
  2. Trevor Carlson
  3.  
  4. > Does anyone have source examples of how to convert an MSBIN to a
  5. > LongInt Type Variable?
  6. }
  7.  
  8. Type
  9.   MKS = Array [0..3] of Byte;
  10.  
  11. Function MStoIEEE(Var MS) : Real;
  12. { Converts a 4 Byte Microsoft format single precision Real Variable as
  13.   used in earlier versions of QuickBASIC and GW-BASIC to IEEE 6 Byte Real }
  14. Var
  15.   m    : MKS Absolute MS;
  16.   r    : Real;
  17.   ieee : Array [0..5] of Byte Absolute r;
  18. begin
  19.   FillChar(r, sizeof(r), 0);
  20.   ieee[0] := m[3];
  21.   ieee[3] := m[0];
  22.   ieee[4] := m[1];
  23.   ieee[5] := m[2];
  24.   MStoieee := r;
  25. end;  { MStoIEEE }
  26.  
  27.  
  28. Function IEEEtoMS(ie : Real) : LongInt;
  29. { LongInt Type used only For convenience of Typecasting. Note that this will
  30.   only be effective where the accuracy required can be obtained in the 23
  31.   bits that are available With the MKS Type. }
  32. Var
  33.   ms    : MKS;
  34.   ieee  : Array [0..5] of Byte Absolute ie;
  35. begin
  36.   ms[3] := ieee[0];
  37.   ms[0] := ieee[3];
  38.   ms[1] := ieee[4];
  39.   ms[2] := ieee[5];
  40.   IEEEtoMS := LongInt(ms);
  41. end; { IEEEtoMS }
  42.